package com.huixh.train.business.controller.admin;

import com.huixh.train.business.req.StationQueryReq;
import com.huixh.train.business.req.StationSaveReq;
import com.huixh.train.business.resp.StationQueryResp;
import com.huixh.train.business.service.StationService;
import com.huixh.train.common.resp.PageResult;
import com.huixh.train.common.resp.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author huixh
 */
@Validated
@Tag(name = "车站管理", description = "车站管理")
@RestController
@RequestMapping("/admin/station")
public class StationController {
    @Resource
    private StationService stationService;

    @PostMapping("/save")
    @Operation(summary = "新增车站/修改", method = "POST")
    public Result<?> save(@RequestBody @Valid StationSaveReq stationSaveReq) {
        stationService.save(stationSaveReq);
        return Result.success();
    }

    @PostMapping("/quest-list")
    @Operation(summary = "查询车站列表", method = "POST")
    public PageResult<List<StationQueryResp>> query(@RequestBody @Valid StationQueryReq stationQueryReq) {
        return stationService.queryList(stationQueryReq);
    }
    @Operation(summary = "删除车站", method = "DELETE")
    @DeleteMapping("/delete/{id}")
    public Result<?> deleteById(@NotNull @PathVariable(name = "id") Long id) {
        stationService.delete(id);
        return Result.success("删除成功");
    }

    @GetMapping("/quest-all")
    @Operation(summary = "查询车站列表", method = "GET")
    public Result<List<StationQueryResp>> queryList() {
        return stationService.getAllList();
    }
}